package Wallpaper::Execute::Scaling;
$VERSION = sprintf "%.3f", 1 + substr(q$Revision: 162 $,9)/1000;

package Wallpaper::Execute;

use Image::Magick;

use Wallpaper::Configuration qw( %datastore );
use Wallpaper::Tools;

sub doscale {
    my ( $display, $image ) = @_;
    my $general_config = Wallpaper::Configuration->general;
    my $display_config = Wallpaper::Configuration->display( $display );
    my $mangle_config  = Wallpaper::Configuration->mangle( $display );
    my ( $height, $width, $original, $res_width, $res_height );

    my $manglefilename = $image->Get( 'filename' );

    ( $res_width, $res_height ) = $display_config->{ 'resolution' } =~ /^(\d+)x(\d+)/;

    if ( $manglefilename =~ /Tile_.*/ ) {
        die "Cannot read blank image :  " . $general_config->{ 'bgdir' } . "/blank.png" if ( !-e $general_config->{ 'bgdir' } . '/blank.png' );
        $image->Read( $general_config->{ 'bgdir' } . '/blank.png' );
        $original = $image->[1];    # Original is blank tiled image ( not [0]! )
        $original->Resize( geometry => "!" . $res_width . "x " . $res_width );    # Create a large container for the collage
        $original->Texture( Texture => $image->[0] );                             # Texture "original" onto blank tile
        shift( @{ $image } );

    } else {
        $original = $image->[0];                                                  # [0] is the photo selected earlier in script, create a ref
    }

  return $original;

} ## end sub doscale

1;
